package com.digital.smartgrow.controller.business;

import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.common.util.WebTool;
import com.digital.smartgrow.dto.business.StartUpDto;
import com.digital.smartgrow.dto.business.UpJobPageDTO;
import com.digital.smartgrow.entity.business.UpBase;
import com.digital.smartgrow.service.business.UpAskService;
import com.digital.smartgrow.service.business.UpBaseService;
import com.digital.smartgrow.vo.businesscenter.MeUpJobInfoVo;
import com.digital.smartgrow.vo.businesscenter.MeUpJobVo;
import com.digital.smartgrow.vo.businesscenter.UpJobVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by SunYuechao on 2022/7/13 下午2:16
 */
@Api(tags = "职称申报")
@RestController
@RequestMapping("${context.prefix}/business/upAsk")
public class UpAskController {

    @Autowired
    private UpAskService upAskService;
    @Autowired
    private UpBaseService upBaseService;
//    @PostMapping("/list")
//    public Object getListByPage(@RequestBody UpJobPageDTO upJobPageDTO){
    @ApiOperation(value = "我的申报列表")
    @PostMapping("/myJob/list")
    public List<MeUpJobVo> myJobListByPage(@RequestBody UpJobPageDTO upJobPageDTO) {
       List<MeUpJobVo> myJobList = upAskService.myJobList(upJobPageDTO);

        return myJobList;
    }
    @ApiOperation(value = "我的申报明细")
    @GetMapping("/myJob/info/{upBaseId}")
    public MeUpJobInfoVo myJobInfo(@PathVariable @ApiParam(value = "申报基数数据ID") Integer upBaseId) {
        MeUpJobInfoVo myJobList = upAskService.myJobInfo(upBaseId);

        return myJobList;
    }

    @ApiOperation(value = "申报列表")
    @PostMapping("/job/list")
    public List<UpJobVo> jobListByPage(@RequestBody UpJobPageDTO upJobPageDTO) {
        List<UpJobVo> upJobVos = upAskService.jobList(upJobPageDTO);
        return upJobVos;
        //return Result.success( upAskService.jobList(upJobPageDTO));
    }
    @ApiOperation(value = "开始申报")
    @PostMapping("/startUp")
    public Object startUpOne(@RequestBody StartUpDto startUpDto) {
        if (startUpDto.getUpBase().getId() == null) return Result.fail("申报基础ID不能为空");
        return Result.success(upAskService.startUpOne(startUpDto));
    }
    @ApiOperation(value = "获取申报ID")
    @GetMapping("/get/base/{upId}")
    public Object getBase(@PathVariable @ApiParam(value = "申报项ID") Integer upId) {
        if (upId == null) return Result.fail("申报项ID不能为空");
        UpBase upBase = new UpBase();
        upBase.setAaa("任现职以来获何表彰与奖励和荣誉称号");
        upBase.setBbb("任现职以来受何处分");
        upBase.setCcc("学习经历");
        upBase.setDdd("工作经历");
        upBase.setEee("进修情况");
        upBase.setFff("参加学术交流情况");
        upBase.setGgg("任现职以来完成教学工作情况");
        upBase.setHhh("指导研究生、进修生、青年教师情况");
        upBase.setIii("教学改革方面的成绩");
        upBase.setJjj("课程建设、实验室建设方面的实绩");
        upBase.setKkk("任现职以来发表、出版论文、论著、教材情况");
        upBase.setLll("任现职以来承担并完成科研任务、取得科研成果情况");
        upBase.setMmm("在校外担任社会工作或服务工作情况");
        upBase.setNnn("从事科技开发、成果推广、科技扶贫情况及其实绩");
        upBase.setOoo("从事科技开发、成果推广、科技扶贫情况及其实绩-附件");
        upBase.setPpp("任现职以来专业实践情况");
        upBase.setQqq("任现职以来担任班主任、辅导员、人生导师等情况");
        upBase.setRrr("任现职以来起草、制定的重要文件、重要报告目录");
        upBase.setSss("本人任现职以来工作总结");
        upBase.setUserId(WebTool.getCurrentUser().getId());
        upBase.setIdcard(WebTool.getCurrentUser().getIdentityNumber());
        upBase.setJobId(upId);
        upBaseService.save(upBase);
        return Result.success(upBase);
    }
   // @ApiOperation(value = "开始申报")
   // @PostMapping("/{upId}")
    public Object startUp(@PathVariable @ApiParam(value = "申报项ID") Integer upId) {
        if (upId == null) return Result.fail("申报项ID不能为空");
        return Result.success(upAskService.startUp(upId));
    }

  //  @ApiOperation(value = "打回重新申报")
    //@PostMapping("/{upId}/{jobLogIdOld}")
    public Object restUp(@PathVariable @ApiParam(value = "申报项ID") Integer upId,@PathVariable @ApiParam(value = "上一次申报流程ID，打回通知里面可获取") Integer jobLogIdOld) {
        if (upId == null) return Result.fail("申报项ID不能为空");
        if (jobLogIdOld == null) return Result.fail("上一次申报流程ID不能为空");
        return Result.success(upAskService.restUp(upId, jobLogIdOld));
    }

    @ApiOperation(value = "获取下一个审批类型,及是否系统已设定")
    @GetMapping("/isRole/{upJobId}")
    public Object getIsRole(@PathVariable @ApiParam(value = "晋升ID") Integer jobLogId) {
        if (jobLogId == null) return Result.fail("晋升ID不能为空");
        return Result.success(upAskService.getIsRole(jobLogId));
    }

    @ApiOperation(value = "通过，并指定下一个审批人")
    @PostMapping("/process/pass/{jobLogId}")
    public Object updateProcess(@PathVariable @ApiParam(value = "晋升ID") Integer jobLogId,
                                @ApiParam(value = "指定审批人ID") @RequestParam(required = false,defaultValue = "-1") Integer checkId,//如果系统已经指定，不需要传入
                                @ApiParam(value = "审批意见") String checkContent) {
        if (jobLogId == null) return Result.fail("晋升ID不能为空");
        if (checkId == null) return Result.fail("指定审批人ID不能为空");
        return Result.success(upAskService.updateProcess(jobLogId, checkId, checkContent));
    }

    @ApiOperation(value = "打回")
    @PostMapping("/process/callback/{jobLogId}")
    public Object callBackProcess(@PathVariable @ApiParam(value = "晋升ID") Integer jobLogId, @ApiParam(value = "审批意见") String checkContent) {
        if (jobLogId == null) return Result.fail("晋升ID不能为空");
        return Result.success(upAskService.callBackProcess(jobLogId, checkContent));
    }

    @ApiOperation(value = "拒绝")
    @PostMapping("/process/block/{jobLogId}")
    public Object deleteProcess(@PathVariable @ApiParam(value = "晋升ID") Integer jobLogId, @ApiParam(value = "审批意见") String checkContent) {
        if (jobLogId == null) return Result.fail("晋升ID不能为空");
        return Result.success(upAskService.deleteProcess(jobLogId, checkContent));
    }


}
